home *** CD-ROM | disk | FTP | other *** search
- class actionscript.Weapon extends MovieClip
- {
- var game;
- var _bulletSpeed;
- var _wLevel;
- var _enemyDetected;
- var _canBePlaced;
- var _SellUpgrade;
- var _type;
- var w_mc;
- var radius;
- var _sdTime;
- var _sdMult;
- var _damage;
- var _upgradeCost;
- var _value;
- var _sellingValue;
- var _delay;
- var _range;
- var rangeCircle;
- var _wCounter;
- var bullet_mc;
- var wInterval;
- var _info;
- var _drag;
- var weapon;
- var cross;
- function Weapon()
- {
- super();
- this.game = this._parent;
- this._bulletSpeed = 700;
- this._wLevel = 1;
- this._enemyDetected = false;
- this._canBePlaced = false;
- this._SellUpgrade = false;
- this.updateWeapon(this._type);
- this.updateInfo();
- this.game.currentWeapon = this;
- this.w_mc.numbers._visible = false;
- this.radius.setMask(this.game.gameMask_mc);
- this.radius._visible = false;
- this.gotoAndStop(this._type);
- }
- function updateWeapon(sType)
- {
- if(sType == "Pepsi")
- {
- this._sdTime = this.game.sdTime[sType + this._wLevel];
- this._sdMult = this.game.sdMult[sType + this._wLevel];
- }
- this._damage = this.game.damage[sType + this._wLevel];
- this._upgradeCost = this.game.upgradeCost[sType + this._wLevel];
- this._value = this.game.wValue[sType + this._wLevel];
- this._sellingValue = Math.floor(this._value / 100 * 75);
- this._delay = this.game.delay[sType + this._wLevel];
- this._range = this.game.range[sType + this._wLevel];
- this.rangeCircle._radius = this._range / 2;
- this.radius._xscale = this.radius._yscale = this._range;
- }
- function upgradeWeapon()
- {
- if(this._wLevel >= 3)
- {
- return undefined;
- }
- this._wLevel = this._wLevel + 1;
- this.w_mc.numbers.gotoAndStop(this._wLevel);
- this.updateWeapon(this._type);
- this.clearWInterval();
- this.updateInfo();
- this.game.interface_mc.checkButtons();
- }
- function sellWeapon()
- {
- this.game.interface_mc.addSubtractMoney(this._sellingValue);
- this.game.interface_mc.closeWeaponOptions(this);
- this.removeWeapon();
- }
- function removeWeapon()
- {
- this.game.trail_mc["WeaponHitArea" + this._wCounter].removeMovieClip();
- this.removeMovieClip();
- }
- function circlesColliding(cCircle1, cCircle2)
- {
- var _loc7_ = cCircle1._xCenter;
- var _loc5_ = cCircle1._yCenter;
- var _loc10_ = cCircle1._radius;
- var _loc6_ = cCircle2._xCenter;
- var _loc3_ = cCircle2._yCenter;
- var _loc9_ = cCircle2._radius;
- var _loc2_ = this.calcDistance(_loc7_,_loc5_,_loc6_,_loc3_);
- if(_loc2_ <= _loc10_ + _loc9_)
- {
- return true;
- }
- return false;
- }
- function calcDistance(p1x, p1y, p2x, p2y)
- {
- var _loc2_ = Math.abs(p1x - p2x);
- var _loc1_ = Math.abs(p1y - p2y);
- var _loc3_ = Math.sqrt(_loc2_ * _loc2_ + _loc1_ * _loc1_);
- return _loc3_;
- }
- function shoot(nx, ny, t_mc)
- {
- var _loc9_ = undefined;
- var _loc7_ = undefined;
- var _loc5_ = undefined;
- var _loc10_ = undefined;
- var _loc3_ = undefined;
- var _loc4_ = undefined;
- var _loc12_ = undefined;
- var _loc2_ = undefined;
- var _loc6_ = undefined;
- var _loc11_ = nx + this._x;
- var _loc8_ = ny + this._y;
- _loc7_ = Math.abs(_loc11_ - this._x);
- _loc5_ = Math.abs(_loc8_ - this._y);
- _loc12_ = Math.atan(_loc5_ / _loc7_);
- _loc2_ = _loc12_ * 180 / 3.141592653589793;
- _loc9_ = Math.sqrt(_loc7_ * _loc7_ + _loc5_ * _loc5_);
- _loc10_ = 20;
- _loc3_ = _loc10_ * _loc7_ / _loc9_;
- _loc4_ = _loc10_ * _loc5_ / _loc9_;
- if(_loc11_ <= this._x)
- {
- if(_loc8_ <= this._y)
- {
- _loc6_ = 1;
- _loc3_ = - _loc3_;
- _loc4_ = - _loc4_;
- }
- else
- {
- _loc6_ = 4;
- _loc3_ = - _loc3_;
- _loc2_ = 360 - _loc2_;
- }
- }
- else if(_loc8_ <= this._y)
- {
- _loc6_ = 2;
- _loc4_ = - _loc4_;
- _loc2_ = 180 - _loc2_;
- }
- else
- {
- _loc6_ = 3;
- _loc2_ += 180;
- }
- this.bullet_mc = this.attachMovie("Bullet","Bullet",this.getNextHighestDepth(),{_damage:this._damage,_type:this._type,_speedX:_loc3_,_speedY:_loc4_,_targetX:nx,_targetY:ny,_rotation:_loc2_,_distance:_loc9_,_wLevel:this._wLevel,_q:_loc6_,tMc:t_mc});
- if(this.wInterval == undefined)
- {
- this.waitTimer(this._delay,this);
- }
- }
- function waitTimer(nDelay, mMc)
- {
- function test()
- {
- if(mMc._enemyDetected)
- {
- mMc._enemyDetected = false;
- }
- else
- {
- mMc.clearWInterval();
- }
- }
- if(this.game._stopped)
- {
- return undefined;
- }
- var _loc2_ = this._delay * 1000;
- this.wInterval = setInterval(test,_loc2_);
- }
- function clearWInterval()
- {
- clearInterval(this.wInterval);
- this.wInterval = undefined;
- this._enemyDetected = false;
- }
- function updateInfo()
- {
- this._info = this._type + ":<br><br> Weapon Level: " + this._wLevel + "<br> Damage: " + this._damage + "<br> Range: " + this._range / 10 + "<br> Rate: " + this._delay + " second(s)" + "<br> Sell for: " + this._sellingValue + " credit(s)";
- if(this._upgradeCost != undefined)
- {
- this._info += "<br> Upgrade cost: " + this._upgradeCost + " credits";
- }
- else
- {
- this._info += "<br> Upgrade cost: Max Level Reached";
- }
- if(this._type == "Pepsi")
- {
- this._info += "<br>Reduce speed by: " + (100 - this._sdMult * 100) + "%<br> Duration:" + this._sdTime + " seconds";
- }
- }
- function onEnterFrame()
- {
- if(this.game._stopped)
- {
- return undefined;
- }
- if(this._drag)
- {
- if(!this.weapon.hitTest(this.game.interface_mc) && !this.radius._visible && this._drag)
- {
- this.radius._visible = true;
- }
- if(this.weapon.hitTest(this.game.interface_mc) && this.radius._visible && this._drag)
- {
- this.radius._visible = false;
- }
- if(!this.game.trail_mc.isColliding(this.cross) && !this._canBePlaced)
- {
- var _loc9_ = this.game.interface_mc;
- var _loc10_ = this.game.textMessages;
- _loc9_.setText(_loc9_.info_txt,_loc10_._wCanBePlaced);
- this.radius._xscale = this.radius._yscale = this._range;
- this.radius.setMask(this.game.gameMask_mc);
- this._canBePlaced = true;
- this.w_mc.numbers._visible = false;
- §§push(this.gotoAndStop(this._type));
- }
- if(this.game.trail_mc.isColliding(this.weapon) && this._canBePlaced)
- {
- _loc9_ = this.game.interface_mc;
- _loc10_ = this.game.textMessages;
- _loc9_.setText(_loc9_.info_txt,_loc10_._wCannotBePlaced);
- this.radius._xscale = this.radius._yscale = this._range;
- this.radius.setMask(this.game.gameMask_mc);
- this._canBePlaced = false;
- §§push(this.gotoAndStop("Red"));
- }
- }
- else if(!this._drag && !this._enemyDetected)
- {
- var _loc2_ = 1;
- while(_loc2_ <= this.game._enemyNumber)
- {
- if(this.game["Enemy" + _loc2_] != undefined && !this.game["Enemy" + _loc2_]._killed)
- {
- var _loc4_ = this.game["Enemy" + _loc2_]._x;
- var _loc3_ = this.game["Enemy" + _loc2_]._y;
- var _loc5_ = new Object({_xCenter:_loc4_,_yCenter:_loc3_,_radius:15});
- if(this.circlesColliding(this.rangeCircle,_loc5_))
- {
- this._enemyDetected = true;
- this.shoot(_loc4_ - this._x,_loc3_ - this._y,this.game["Enemy" + _loc2_]);
- }
- }
- if(this._enemyDetected)
- {
- return undefined;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- }
- function onMouseMove()
- {
- if(this._drag)
- {
- setProperty(this, _X, this._parent._xmouse);
- setProperty(this, _Y, this._parent._ymouse);
- updateAfterEvent();
- }
- }
- function onRollOver()
- {
- if(!this._drag && !this._SellUpgrade)
- {
- var _loc3_ = undefined;
- var _loc2_ = this.game.interface_mc;
- if(this.game._SellUpgrade)
- {
- _loc3_ = this.game.textMessages._weaponOptions;
- }
- else
- {
- _loc3_ = this.game.textMessages._weaponOver;
- }
- _loc2_.setText(_loc2_.info_txt,this._info);
- _loc2_.setText(_loc2_.info2_txt,_loc3_);
- }
- }
- function onRollOut()
- {
- if(!this._drag && !this._SellUpgrade)
- {
- this.game.interface_mc.setText(this.game.interface_mc.info_txt,"");
- this.game.interface_mc.setText(this.game.interface_mc.info2_txt,"");
- }
- }
- function onRelease()
- {
- if(this.game._stopped)
- {
- return undefined;
- }
- if(!this._drag)
- {
- var _loc2_ = this.game.interface_mc;
- if(!this.radius._visible)
- {
- if(this.game.currentWeapon != undefined)
- {
- _loc2_.closeWeaponOptions(this.game.currentWeapon);
- }
- this.w_mc.gotoAndPlay("play");
- this.game.currentWeapon = this;
- this.game._SellUpgrade = true;
- var _loc3_ = this.game.textMessages._weaponOptions;
- _loc2_.setText(_loc2_.info2_txt,_loc3_);
- _loc2_.attachWeaponOptions(this);
- this.radius._visible = true;
- this.swapDepths(this._parent.getNextHighestDepth());
- }
- else
- {
- _loc2_.closeWeaponOptions(this);
- }
- }
- else
- {
- if(!this._canBePlaced)
- {
- return undefined;
- }
- if(this.weapon.hitTest(this.game.interface_mc))
- {
- this.game._draggingWeapon = false;
- this.removeMovieClip();
- return undefined;
- }
- if(!this.hitTest(this.game.interface_mc))
- {
- }
- this._drag = this.game._draggingWeapon = false;
- this.game.trail_mc.attachWeaponHitArea(this._x,this._y,this);
- this.onMouseMove = undefined;
- this.w_mc.numbers._visible = true;
- this.game.interface_mc.addSubtractMoney(- this._value);
- this.game.currentWeapon = undefined;
- this.rangeCircle = new Object({_xCenter:this._x,_yCenter:this._y,_radius:this._range / 2});
- this.radius._visible = false;
- }
- }
- }
-